<?php


class SeosController extends \BaseController {

	/**
	 * Display a listing of seos
	 *
	 * @return Response
	 */
	public function index()
	{
		$seos = Seo::all();

		return View::make('seos.index', compact('seos'));
	}

	/**
	 * Show the form for creating a new seo
	 *
	 * @return Response
	 */
	public function create()
	{
		return View::make('seos.create');
	}

	/**
	 * Store a newly created seo in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
                $seo = new Seo;
                
		if (!$seo->validate(Input::all()))
		{
			return Redirect::back()->withErrors($seo->errors)->withInput();
		}

                $seo->setExistValues(array('keywords' , 'description' , 'seoble_id' , 'seoble_type') , true);
                $seo->save();

		return Redirect::to('topics');
	}

	/**
	 * Display the specified seo.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		$seo = Seo::findOrFail($id);

		return View::make('seos.show', compact('seo'));
	}

	/**
	 * Show the form for editing the specified seo.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		$seo = Seo::find($id);

		return View::make('seos.edit', compact('seo'));
	}

	/**
	 * Update the specified seo in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		$seo = Seo::findOrFail($id);

		if ($seo->validate(Input::all()))
		{
                    $seo->setExistValues(array('keywords' , 'description') , true);
                    $seo->save();
		}else {
                       return Redirect::back()->withErrors($seo->errors)->withInput();
                }
                
                
		//$seo->update(Input::all());

		return Redirect::to('topics');
	}

	/**
	 * Remove the specified seo from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		Seo::destroy($id);

		return Redirect::route('seos.index');
	}

}
